package gameObjects
{
	import Box2D.Collision.Shapes.b2Shape;
	import Box2D.Common.Math.b2Vec2;
	import Box2D.Dynamics.b2Body;
	import Box2D.Dynamics.b2FixtureDef;
	import physics.PhysicsManager;
	/**
	 * ...
	 * @author ...
	 */
	public class Wall extends GameObject
	{
		/* private const/var */
		private const sHORIZONTAL:String = "H";
		private const sVERTICAL:String = "V";
		private const sSQUARE:String = "S";
		private const sORIENTED:String = "O";
		
		private const nDENSITY:Number = 0.0;
		private const nRESTITUTION:Number = 0.5;
		private const nFRICTION:Number = 10.0;
		private const uiBODY_TYPE:uint = b2Body.b2_staticBody;
		
		private var m_physicsMgr:PhysicsManager = null;
		private var m_sType:String = ""; // what type of wall is being created from the parameters given
		private var m_nX:Number = 0;
		private var m_nY:Number = 0;
		private var m_nWidth:Number = 0;
		private var m_nHeight:Number = 0;
		private var m_nDegRotation:Number = 0;
		
		/* public functions */
		public function Wall(phyMgr:PhysicsManager, nX:Number, nY:Number, nWidth:Number, nHeight:Number, nDegRotation:Number, uiTag:uint = 	Globals.uiTAG_STATIC_WALL)
		{
			tag = uiTag;
			m_physicsMgr = phyMgr;
			m_nX = nX;
			m_nY = nY;
			m_nDegRotation = nDegRotation;
			m_nWidth = nWidth;
			m_nHeight = nHeight;
			
			setOriginalValues(nX, nY, nWidth, nHeight, nDegRotation);
			
			if (nWidth > nHeight)
			{
				m_sType = sHORIZONTAL;
				createHorizontalBody();
			}
			if (nWidth < nHeight)
			{
				m_sType = sVERTICAL;
				createVerticalBody();
			}
			if (nWidth == nHeight)
			{
				m_sType = sSQUARE;
				createSquareBody();
			}
			
			if (nDegRotation != 0)
			{
				m_sType = sORIENTED;
				createOrientedBody();
			}
			
			if (body)
			{
				body.SetUserData(this);
			}
		}
		
		public function get type():String
		{
			return m_sType;
		}
		
		/* private functions */
		private function createHorizontalBody():void
		{
			var wallHorShape:b2Shape = m_physicsMgr.createAABBShape(m_nWidth, m_nHeight);
			var wallHorFixtureDef:b2FixtureDef = m_physicsMgr.createFixtureDef(wallHorShape, nDENSITY, nRESTITUTION, nFRICTION, false);
			body = m_physicsMgr.createBody(m_nX, m_nY, uiBODY_TYPE, wallHorFixtureDef);
		}
		
		private function createVerticalBody():void
		{
			var wallVerShape:b2Shape = m_physicsMgr.createAABBShape(m_nWidth, m_nHeight);
			var wallVerFixtureDef:b2FixtureDef = m_physicsMgr.createFixtureDef(wallVerShape, nDENSITY, nRESTITUTION, nFRICTION, false);
			body = m_physicsMgr.createBody(m_nX, m_nY, uiBODY_TYPE, wallVerFixtureDef);
		}
		
		private function createSquareBody():void
		{
			var wallBoxShape:b2Shape = m_physicsMgr.createAABBShape(m_nWidth, m_nHeight);
			var wallBoxFixtureDef:b2FixtureDef = m_physicsMgr.createFixtureDef(wallBoxShape, nDENSITY, nRESTITUTION, nFRICTION, false);
			body = m_physicsMgr.createBody(m_nX, m_nY, uiBODY_TYPE, wallBoxFixtureDef);
		}
		
		private function createOrientedBody():void
		{
			var wallOrientedShape:b2Shape = m_physicsMgr.createOrientedBoxShape(m_nWidth, m_nHeight, new b2Vec2(0, 0), CommonMath.degreeToRadian(m_nDegRotation));
			var wallOrientedFixtureDef:b2FixtureDef = m_physicsMgr.createFixtureDef(wallOrientedShape, nDENSITY, nRESTITUTION, nFRICTION, false);
			body = m_physicsMgr.createBody(m_nWidth, m_nHeight, uiBODY_TYPE, wallOrientedFixtureDef);
		}
	}

}